<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2023/3/2
  Time: 11:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>部门更新</title>
    <script type="text/javascript" src="/js/jquery-3.4.1.min.js"></script>
</head>
<body>
<h3 align='center'>部门更新</h3>
<div id="error" style="color: red;text-align: center"></div>
<form id="deptFrm">
    <table border="1" width="400px" align="center">
        <input type="hidden" id="deptNo" name="deptNo">
        <tr>
            <td>部门名称:</td>
            <td><input type="text" id="deptName" name="deptName"></td>
        </tr>
        <tr>
            <td>部门位置:</td>
            <td><input type="text" id="loc" name="loc"></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input type="button" id="btn" value="修改"></td>
        </tr>
    </table>
</form>
<script>
    let deptNo = ${param.deptNo};
    //alert(deptNo);
    $(function () {
        $.ajax({
            url: "/DeptServlet/queryById",
            type: "get",
            //dataType:"json",
            data: {deptNo: deptNo},
            contentType: "json",
            success: function (data) {
                $("#deptNo").val(data.deptNo);
                $("#deptName").val(data.deptName);
                $("#loc").val(data.loc);
            },
            error: function (data) {
            }
        });
        $("#btn").click(function () {
            var dept = $("#deptFrm").serialize();
            $.ajax({
                url: "/DeptServlet/update",
                type: "get",
                //dataType:"json",
                data: dept,
                contentType: "json",

                success: function (data) {
                    if (data > 0) {
                        location.href = "/dept/page.jsp";
                    } else {
                        $("#error").html("添加失败！");
                    }
                },
                error: function (data) {
                }
            });
        })
    });
</script>
</body>
</html>
